﻿using IBLL;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Model;
using System;


namespace WebApplication3.Controllers
{
    public class login : Controller
    {
        public string id;
        private IStudentBll _Isdb;
        public login(IStudentBll Isdb)
        {
            _Isdb = Isdb;
        }
        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public async Task<IActionResult> Index(string account, string password)
        {
            var data = _Isdb.SignInAsync(account, password);
            if (data != null)
            {

                this.id = data.Id.ToString();
                return RedirectToAction("quan");
            }
            return RedirectToAction("Index");

        }
        public IActionResult quan()
        {
            var data = _Isdb.GetStudentIdAsync(Guid.Parse(id));
            ViewBag["Sto"] = data;
            return View();
        }
        [HttpGet]
        public IActionResult Edit(Guid id)
        {
            var data = _Isdb.GetStudentIdAsync(id);
            ViewBag["Stu"] = data;
            return View();
        }
        [HttpPost]
        public IActionResult Edit(Students stu)
        {
            if (stu != null)
            {
                _Isdb.EditAsync(stu.Id, stu.name, stu.birthday, stu.gender, stu.tel, stu.email, stu.qqNumber, stu.address, stu.gradesId, stu.qwd, stu.photo);
                return RedirectToAction("quan");
            }
            return View();
        }
    }
}
